<?php
//---------------------------------------------------------------------------------------------------------------------------
    include_once($config['app_dir'] . '/includes/object.class.php');
    include_once($config['app_dir'] . '/includes/template.class.php');
    include_once($config['app_dir'] . '/includes/list.class.php');
    //------------------------------------------------------------------------------------------------------------------------
    class objParamItem extends objObject implements iDebug{
            public $name = false;
            public $value = false;
            public $flag = false;
            public $group = false;

        function __construct($name, $value, $flag=false, $group=false) {
            $this->name = $name;
            $this->value = $value;
            $this->flag = $flag;
            $this->group = $group;
        }//class constructor

        public function ClassName() {
            return  __CLASS__;
        }//ClassName

        function getAssocArray() {
            $reslut = array();
            $result['name'] = $this->name;
            $result['value'] = $this->value;
            $result['flag'] = $this->flag;
            $result['group'] = $this->group;
            return $result;
        }//getAssocArray

        function isEmpty() {
            return !$this->name;
        }//isEmpty

        function dump() {
            echo "\n Item dump\n";
            echo "\n name: ";var_dump($this->name);
            echo "\n value: ";var_dump($this->value);
            echo "\n flag: ";var_dump($this->flag);
            echo "\n group: ";var_dump($this->group);
        }//dump

   }//class objParamItem
   //------------------------------------------------------------------------------------------------------------------------
   class objParamList extends objIndexList implements  iDebug, Iterator, ArrayAccess{
            protected $id;
            protected $db = false;

        function __construct($id) {
            $this->id = $id;
        }//class constructor

        public function ClassName() {
            return  __CLASS__;
        }//ClassName


        function build(&$db, $query, $field_value='value', $field_name='name', $field_flag='flag', $field_group='group', $clear=true) {
            $rs = $db->Execute($query);
            if ( !$rs ) {
                echo "<h3>Помилка запиту: $query</h3>";
                return false;
            }

            if( $clear ) $this->clear();
            $rs->MoveFirst();
            $ff = false;
            $fg = false;
            if( $field_flag ) $ff = array_key_exists($field_flag, $rs->fields);
            if( $field_group ) $fg = array_key_exists($field_group, $rs->fields);
            while( ! $rs->EOF ) {
                if( $ff ) $flag_value = $rs->fields[$field_flag]; else $flag_value=false;
                if( $fg ) $group_value = $rs->fields[$field_group]; else $group_value=false;
                $this->add(new objParamItem($rs->fields[$field_name], $rs->fields[$field_value],  $flag_value, $group_value));

//            adodb_movenext($rs); ## ADODB extension function
                $rs->MoveNext();
            } //while
            return !$this->isEmpty();
        }//build

        function item($value) {
            foreach($this-> items as $item)
                if ($item->value == $value) return $item;
        }//item

        function getAssocArray() {
            $reslut = array();
            foreach($this-> items as $item)
                $result[] = $item->getAssocArray();
            return $result;
        }//getAssocArray

    }//class objParamList
//---------------------------------------------------------------------------------------------------------------------------
?>
